package com.oocl.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.exception.MyException;
import com.oocl.pojo.Book;
import com.oocl.service.BookService;
import com.oocl.service.impl.BookServiceFactory;
import com.oocl.service.impl.ServiceFactory;

/**
 * Servlet implementation class ItemsServlet
 */
public class ItemsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		try {
			BookServiceFactory factory = (BookServiceFactory) ServiceFactory
					.getServiceFactory(BookServiceFactory.BOOK);
			BookService  pSer = factory.getService();
			List<Book> list = pSer.getBooks();
			request.setAttribute("list", list);
		    request.getRequestDispatcher("items.jsp").forward(request, response);
		} catch (MyException e) {
			e.printStackTrace();
		}
        
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
	    
		doGet(request,response);
	}
	

}
